package engine.system;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.util.ArrayList;

public final class MADSystem {
	
	public static Dimension getScreenSize(){
		return Toolkit.getDefaultToolkit().getScreenSize(); 
	}
	
	public static Dimension centerToScreen(int w, int h){
		int x = (int) ((getScreenSize().getWidth() - w) / 2) ;
		int y = (int) ((getScreenSize().getHeight() - h) / 2) ; 
		return new Dimension(x, y); 
	}

	private static int spc_count=-1;
	
	public static void getAllFilesFromDirectory(File aFile, ArrayList<File> files, String mask) {
		spc_count++;
		String spcs = "";
		for (int i = 0; i < spc_count; i++)
			spcs += " ";
		if (aFile.isFile() && hasExtension(aFile, mask)){
//			System.out.println(spcs + "[FILE] " + getFileName(aFile)+", Extension: "+getFileExtension(aFile));
			files.add(aFile);
		}else if (aFile.isDirectory()) {
//			System.out.println(spcs + "[DIR] " + aFile.getName());
			File[] listOfFiles = aFile.listFiles();
			if (listOfFiles != null) {
				for (int i = 0; i < listOfFiles.length; i++)
					getAllFilesFromDirectory(listOfFiles[i], files, mask);
			} else {
//				System.out.println(spcs + " [ACCESS DENIED]");
			}
		}
		spc_count--;
	}

	public static String getFileExtension(File aFile){
		String ext = "" ; 
		if(aFile.isFile()){
			int i = aFile.getName().lastIndexOf('.'); 
			if(i>0) ext = aFile.getName().substring(i+1); 
		}
		return ext ; 
	}
	
	public static String getFileName(File aFile){
		String fileName = aFile.getName();
		if(aFile.isFile()){
			int i = fileName.lastIndexOf('.') ; 
			fileName = fileName.substring(0,i);
		}
		return fileName ; 
	}
	
	public static boolean hasExtension(File aFile, String mask){
		return getFileExtension(aFile).toLowerCase().equals(mask.toLowerCase()) ; 
	}
	
}
